package com.zaizai.zaizai_good.controller;
import java.util.List;

import com.zaizai.zaizai_good.domain.R;
import com.zaizai.zaizai_good.service.IGoodService;
import com.zaizai.zaizai_good.utils.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zaizai.zaizai_good.domain.pojo.Good;

/**
 * 商品Controller
 * 
 * @author lql
 * @date 2024-10-03
 */
@RestController
@RequestMapping("/goods")
public class GoodController extends BaseController
{
    @Autowired
    private IGoodService goodService;

    /**
     * 查询商品列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Good good)
    {
        startPage();
        List<Good> list = goodService.selectGoodList(good);
        return getDataTable(list);
    }

    /**
     * 获取商品详细信息
     */
    @GetMapping(value = "/{id}")
    public R<Good> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(goodService.selectGoodById(id));
    }

    /**
     * 新增商品
     */
    @PostMapping
    public R<Integer> add(@RequestBody Good good)
    {
        return R.ok(goodService.insertGood(good));
    }

    /**
     * 修改商品
     */
    @PutMapping
    public R<Integer> edit(@RequestBody Good good)
    {
        return R.ok(goodService.updateGood(good));
    }

    /**
     * 删除商品
     */
	@DeleteMapping("/{ids}")
    public R<Integer> remove(@PathVariable Long[] ids)
    {
        return R.ok(goodService.deleteGoodByIds(ids));
    }
}
